﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Model;

namespace CarParking
{
    public partial class frmCarParking : Form
    {
        public Car car = null;
        public frmCarParking()
        {
            InitializeComponent();
        }

        private void btnO_Click(object sender, EventArgs e)
        {
            
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            
        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void txtCarName_TextChanged(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void 入库ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmMain frm = new frmMain();
            if (frm.ShowDialog() == DialogResult.OK)
            {
                Car car = frm.car;
                if (BLL.CarService.AddCar(car))
                    MessageBox.Show("车辆入库登记成功！", "系统提示");
                else
                    MessageBox.Show("车辆入库登记失败！", "系统提示");
            }
        }

        private void 出库ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmOutParking frm = new frmOutParking();
            if (frm.ShowDialog() == DialogResult.OK)
            {
                Car car = frm.car;
                if (BLL.CarService.OutCar(car) != null)
                {
                    System.TimeSpan b = car.EndTime - BLL.CarService.OutCar(car);
                    car.bill = (b.Hours * 3)+10;
                    MessageBox.Show(String.Format("您一共需要支付{0}元",car.bill));
                    BLL.CarService.OUTParking(car);
                    MessageBox.Show("车辆出库成功！", "系统提示");
                }
                else
                    MessageBox.Show("车辆出库失败！", "系统提示");
            }
        }

        private void frmCarParking_Load(object sender, EventArgs e)
        {

        }
    }
}
